package com.zhy.generator.codegen.internal.tableattribute;

import com.zhy.generator.codegen.api.IntrospectedTable;
import com.zhy.generator.config.ConfigurationConstant;

public class XmlAttributes {


    private IntrospectedTable introspectedTable;

    public XmlAttributes(IntrospectedTable introspectedTable){
        this.introspectedTable = introspectedTable;
    }

    public void calculateXmlAttributes() {
        setMyBatis3XmlMapperFileName(calculateMyBatis3XmlMapperFileName());
        setMyBatis3XmlMapperPackage(calculateSqlMapPackage());
        setMyBatis3FallbackSqlMapNamespace(calculateMyBatis3FallbackSqlMapNamespace());

        setCountByExampleStatementId("countByExample"); //$NON-NLS-1$
        setDeleteByExampleStatementId("deleteByExample"); //$NON-NLS-1$
        setDeleteByPrimaryKeyStatementId("deleteByPrimaryKey"); //$NON-NLS-1$
        setInsertStatementId("add"); //$NON-NLS-1$
        setInsertSelectiveStatementId("addSelective"); //$NON-NLS-1$
        setSelectAllStatementId("getAll"); //$NON-NLS-1$
        setSelectByExampleStatementId("getByExample"); //$NON-NLS-1$
        setSelectByExampleWithBLOBsStatementId("getByExampleWithBLOBs"); //$NON-NLS-1$
        setSelectByPrimaryKeyStatementId("getByPrimaryKey"); //$NON-NLS-1$
        setUpdateByExampleStatementId("updateByExample"); //$NON-NLS-1$
        setUpdateByExampleSelectiveStatementId("updateByExampleSelective"); //$NON-NLS-1$
        setUpdateByExampleWithBLOBsStatementId("updateByExampleWithBLOBs"); //$NON-NLS-1$
        setUpdateByPrimaryKeyStatementId("updateByPrimaryKey"); //$NON-NLS-1$
        setUpdateByPrimaryKeySelectiveStatementId("updateByPrimaryKeySelective"); //$NON-NLS-1$
        setUpdateByPrimaryKeyWithBLOBsStatementId("updateByPrimaryKeyWithBLOBs"); //$NON-NLS-1$
        setBaseResultMapId("BaseResultMap"); //$NON-NLS-1$
        setResultMapWithBLOBsId("ResultMapWithBLOBs"); //$NON-NLS-1$
        setExampleWhereClauseId("Example_Where_Clause"); //$NON-NLS-1$
        setBaseColumnListId("Base_Column_List"); //$NON-NLS-1$
        setBlobColumnListId("Blob_Column_List"); //$NON-NLS-1$
        setMyBatis3UpdateByExampleWhereClauseId("Update_By_Example_Where_Clause"); //$NON-NLS-1$
    }

    public String calculateSqlMapPackage() {
        StringBuilder sb = new StringBuilder();
        String pakkage = introspectedTable.calculateJavaPackage(ConfigurationConstant.CONFIGURATION_SQLMAP);
        sb.append(pakkage);
        return sb.toString();
    }

    public String calculateMyBatis3XmlMapperFileName() {
        StringBuilder sb = new StringBuilder();
        sb.append(introspectedTable.getDomainObjectName());
        sb.append("Mapper.xml"); //$NON-NLS-1$
        return sb.toString();
    }
    public String calculateMyBatis3FallbackSqlMapNamespace() {
        StringBuilder sb = new StringBuilder();
        sb.append(calculateSqlMapPackage());
        sb.append('.');
        sb.append(introspectedTable.getDomainObjectName());
        sb.append("Mapper"); //$NON-NLS-1$
        return sb.toString();
    }


    public void setMyBatis3XmlMapperFileName(String mybatis3XmlMapperFileName) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_MYBATIS3_XML_MAPPER_FILE_NAME, mybatis3XmlMapperFileName);
    }

    public void setMyBatis3XmlMapperPackage(String mybatis3XmlMapperPackage) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_MYBATIS3_XML_MAPPER_PACKAGE, mybatis3XmlMapperPackage);
    }

    public void setMyBatis3FallbackSqlMapNamespace(String sqlMapNamespace) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_MYBATIS3_FALLBACK_SQL_MAP_NAMESPACE, sqlMapNamespace);
    }

    public void setCountByExampleStatementId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_COUNT_BY_EXAMPLE_STATEMENT_ID, s);
    }

    public void setDeleteByExampleStatementId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_DELETE_BY_EXAMPLE_STATEMENT_ID, s);
    }

    public void setDeleteByPrimaryKeyStatementId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_DELETE_BY_PRIMARY_KEY_STATEMENT_ID, s);
    }

    public void setInsertStatementId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_INSERT_STATEMENT_ID, s);
    }

    public void setInsertSelectiveStatementId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_INSERT_SELECTIVE_STATEMENT_ID, s);
    }

    public void setSelectAllStatementId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_SELECT_ALL_STATEMENT_ID, s);
    }

    public void setSelectByExampleStatementId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_SELECT_BY_EXAMPLE_STATEMENT_ID, s);
    }

    public void setSelectByExampleWithBLOBsStatementId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_SELECT_BY_EXAMPLE_WITH_BLOBS_STATEMENT_ID, s);
    }

    public void setSelectByPrimaryKeyStatementId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_SELECT_BY_PRIMARY_KEY_STATEMENT_ID, s);
    }

    public void setUpdateByExampleStatementId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_UPDATE_BY_EXAMPLE_STATEMENT_ID, s);
    }

    public void setUpdateByExampleSelectiveStatementId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_UPDATE_BY_EXAMPLE_SELECTIVE_STATEMENT_ID, s);
    }

    public void setUpdateByExampleWithBLOBsStatementId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_UPDATE_BY_EXAMPLE_WITH_BLOBS_STATEMENT_ID, s);
    }

    public void setUpdateByPrimaryKeyStatementId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_UPDATE_BY_PRIMARY_KEY_STATEMENT_ID, s);
    }

    public void setUpdateByPrimaryKeySelectiveStatementId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_UPDATE_BY_PRIMARY_KEY_SELECTIVE_STATEMENT_ID, s);
    }

    public void setUpdateByPrimaryKeyWithBLOBsStatementId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_UPDATE_BY_PRIMARY_KEY_WITH_BLOBS_STATEMENT_ID, s);
    }

    public void setBaseResultMapId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_BASE_RESULT_MAP_ID, s);
    }

    public void setResultMapWithBLOBsId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_RESULT_MAP_WITH_BLOBS_ID, s);
    }

    public void setExampleWhereClauseId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_EXAMPLE_WHERE_CLAUSE_ID, s);
    }

    public void setBaseColumnListId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_BASE_COLUMN_LIST_ID, s);
    }

    public void setBlobColumnListId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_BLOB_COLUMN_LIST_ID, s);
    }

    public void setMyBatis3UpdateByExampleWhereClauseId(String s) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_MYBATIS3_UPDATE_BY_EXAMPLE_WHERE_CLAUSE_ID, s);
    }
}
